package com.example.qxfw.dataBaseManager.nyzjk.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.ny.AgriWeatherDistRecord;
import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.dataBaseManager.nyzjk.service.QxzhlskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/6  星期四   3:03
 * @description : 此类用来 气象灾害历史库
 ***************************************/
@ApiIgnore
@Slf4j
@Api(tags = "数据库管理-农业专家库-气象灾害历史库")
@RestController
@CrossOrigin
@RequestMapping("/QxzhlskController")
public class QxzhlskController {

    @Autowired
    private QxzhlskService qxzhlskService;

    @ApiOperation("查询所有的农业气象灾害记录")
    @GetMapping("selectAll")
    public SysResult selectAll(){
        List<AgriWeatherDistRecord> agriWeatherDistRecordList = this.qxzhlskService.selectAll();
        return SysResult.success(agriWeatherDistRecordList);
    }

    @ApiOperation("查询灾害种类")
    @GetMapping("getDisasterType")
    public SysResult getDisasterType(){
        List<AgriWeatherDistRecord> records = this.qxzhlskService.getDisasterType();
        return SysResult.success(records);
    }

    @ApiOperation("查询站点")
    @GetMapping("selectStationInfo")
    public SysResult selectStationInfo(){
        List<StationInfo> station_info = this.qxzhlskService.selectStationInfo("stationid,stationname", "station_info", null, null, null);
        return SysResult.success(station_info);
    }

    @ApiOperation("添加")
    @PostMapping("addAgriWeather")
    public SysResult addAgriWeather(@RequestBody AgriWeatherDistRecord agriWeatherDistRecord){
        List<AgriWeatherDistRecord> agriWeatherDistRecords = this.qxzhlskService.selectAgriWeatherDistRecord("id", "agri_weather_dist_record", null, "id desc", 1);
        String idMax = agriWeatherDistRecords.get(0).getId();
        agriWeatherDistRecord.setId(idMax);
        Integer integer = this.qxzhlskService.saveAgriWeatherDistRecord(agriWeatherDistRecord);
        if (integer>0){
            return SysResult.success();
        }else {
            return SysResult.fail();
        }
    }

    @ApiOperation("更新")
    @PostMapping("updateAgriWeather")
    public SysResult updateAgriWeather(@RequestBody AgriWeatherDistRecord agriWeatherDistRecord){
        Integer integer = this.qxzhlskService.updateAgriWeatherDistRecord(agriWeatherDistRecord);
        if (integer>0){
            return SysResult.success();
        }else {
            return SysResult.fail();
        }
    }

    @ApiOperation("删除")
    @PostMapping("deleteAgriWeather")
    public SysResult deleteAgriWeather(int id){
        Integer integer = this.qxzhlskService.deleteAgriWeatherDistRecord(id);
        if (integer>0){
            return SysResult.success();
        }else {
            return SysResult.fail();
        }
    }






}
